require 'mu_api'

# Sample to create a continuous run of an analysis
#
# Create the API object
api = Mu_Api.new

# Set host, username, password for the mu4000:
# api.host = "10.10.5.71"
# api.username = "admin"
# api.password = "secret"

# Alternatively,
# EXPORT MU_IP=10.10.5.71; EXPORT MU_USER=admin; EXPORT MU_PASS=secret


# Run an existing template that you've already loaded
# Begin loop
count = 0
while 1
  count += 1
  newname = "rerun #{count}"

  # You will need to get the uuid from the existing template
  uuid = "0f10aadc-5ffb-41cd-b4d7-726a59275fc8"
  status = api.run(uuid, newname); puts "Run Status: #{status}"

  # wait for analysis to start, then poll until it's done
  # my default values poll up to 25 minutes for the analysis to complete
  sleep 30
  100.times do |poll|
    status = api.status
    break unless status =~ /(RUNNING|QUEUED)/
    sleep 15
  end

end
